package com.panopset.swing;

import com.panopset.UtilIO;

/**
 * Field value that is stored in a given file.
 *
 * @author Karl Dinwiddie
 *
 */
public final class FileValue extends FieldValue {

    /**
     * File.
     */
    private String rf;

    /**
     * @param relativePath
     *            File relative path.
     */
    public FileValue(final String relativePath) {
        rf = relativePath;
    }

    /**
     * @param relativePath
     *            File relative path.
     */
    public void setRelativePath(final String relativePath) {
        rf = relativePath;
    }

    @Override
    public String getValue() {
        return UtilIO.getFileText(UtilIO.createFileFromDirectory(Scaffolding.s
                .getHome(), rf));
    }

    @Override
    public void setValue(final String value) {
        UtilIO.saveStringToFile(value, UtilIO.createFileFromDirectory(
                Scaffolding.s.getHome(), rf));
    }
}
